#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
const int N=2e5+5;
int T,n;
int a[N],v[N];
ull ans;
int read(){
	int x;
	scanf("%d",&x);
	return x;
}
void dfs(int d){
	if(d==n){
		int x1=0,y1=0;
		ull t=0;
		for(int i=n;i>=1;i--){
			if(v[i]==1){
				if(x1==a[i])t+=a[i];
				x1=a[i];
			}
			else{
				if(y1==a[i])t+=a[i];
				y1=a[i];
			}
		}
		ans=max(ans,t);
		return;
	}
	for(int i=1;i<=2;i++){
		v[d+1]=i;
		dfs(d+1);
		v[d+1]=0;
	}
}
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	T=read();
	while(T--){
		memset(a,0,sizeof a);
		n=read();
		ans=0;
		for(int i=1;i<=n;i++){
			int x=read();
			a[i]=x;
		}
		dfs(0);
		printf("%llu\n",ans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
